#pragma once

#include "cmd.h"
#include <dirent.h>
#include <sys/stat.h>

//use <dbname>

extern std::string usingdb;

class Use{
private:
    std::vector<std::string> cmd;
public:
    Use(std::vector<std::string> a) : cmd(a){}
    void execute(){
        std::string pathname = "../data/";
        int ret = 0;
        DIR * mydir = nullptr;
        pathname += cmd[1];
        mydir = opendir(pathname.c_str()); 
        if(mydir == nullptr){
            std::cout<<"Unknown database '"<< cmd[1]<< "'"<<std::endl;
        }
        else{
            std::cout<<"Database changed"<<std::endl;
            usingdb = cmd[1];
        }

        closedir(mydir);
    }
};